package com.tan.androidtest.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.tan.androidtest.R;
import com.tan.androidtest.anim.TestAnimWithTouchEventActivity;
import com.tan.androidtest.anim.TestLayoutAnimationActivity;
import com.tan.androidtest.anim.property.TestViewPropertyAnimatorActivity;
import com.tan.androidtest.customview.TestCustomViewActivity;
import com.tan.androidtest.drawable.TestClipDrawableActivity;
import com.tan.androidtest.drawable.TestDrawableActivity;
import com.tan.androidtest.io.TestFileIOActivity;
import com.tan.androidtest.launchMode.TestActivityA;
import com.tan.androidtest.launchactivity.TestLaunchActivity;
import com.tan.androidtest.materialdesign.TestCoordinatorLayoutActivity;
import com.tan.androidtest.materialdesign.TestFloatingActionButtonActivity;
import com.tan.androidtest.process.TestActivityConnectServiceActivity;
import com.tan.androidtest.process.TestMultiProcessActivity;
import com.tan.androidtest.socket.TestSimpleSocketClientActivity;
import com.tan.androidtest.socket.TestSocketClientActivity;
import com.tan.androidtest.traceview.TestTraceViewActivity;
import com.tan.androidtest.viewaction.TestViewActionConflictActivity;
import com.tan.androidtest.viewaction.TestViewActionDispatchActivity;

public class MainActivity extends Activity implements AdapterView.OnItemClickListener {

    private String[] mainArr;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    /**
     * 初始化view
     */
    private void initView() {
        mainArr = getResources().getStringArray(R.array.main_list);
        ListView lv_test = (ListView) findViewById(R.id.lv_test);
        MyAdapter adapter = new MyAdapter();
        lv_test.setAdapter(adapter);
        lv_test.setOnItemClickListener(this);
        //用于测试AIDL 注意: AIDL可以是在本app内,也可以是和别的APP
        /*Intent intent = new Intent(getApplicationContext(), TestAIDLService.class);
        startService(intent);*/
    }

    /**
     * 适配器
     */
    private class MyAdapter extends BaseAdapter {


        @Override
        public int getCount() {
            return mainArr != null ? mainArr.length : 0;
        }

        @Override
        public Object getItem(int i) {
            return mainArr[i];
        }

        @Override
        public long getItemId(int i) {
            return i;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            Holder holder;
            if (view == null) {
                holder = new Holder();
                view = LayoutInflater.from(MainActivity.this).inflate(R.layout.item_main_list_layout, viewGroup, false);
                holder.tv_content = (TextView) view.findViewById(R.id.tv_content);
                view.setTag(holder);
            } else {
                holder = (Holder) view.getTag();
            }
            holder.tv_content.setText(mainArr[i]);
            return view;
        }

        class Holder {
            TextView tv_content;
        }

    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
        switch (i) {
            case 0: {//测试Matisse图片选择框架
                startActivity(new Intent(getApplicationContext(), TestMatisseActivity.class));
                break;
            }
            case 1: {//测试图片在不同目录下(mipmap-mdpi、mipmap-xdpi、mipmap-xxdpi)系统自动放大缩小
                startActivity(new Intent(getApplicationContext(), TestMultiFileImageActivity.class));
                break;
            }
            case 2: {//测试6.0之后悬浮窗的权限申请
                startActivity(new Intent(getApplicationContext(), TestXuanFuWindowPermmisonActivity.class));
                break;
            }
            case 3: {
                startActivity(new Intent(getApplicationContext(), TestCheckSelfPermissionActivity.class));
                break;
            }
            case 4: {//测试Fragment的懒加载
                startActivity(new Intent(getApplicationContext(), TestLazyFragmentActivity.class));
                break;
            }
            case 5: {//测试AlarmManager实现定时任务
                startActivity(new Intent(getApplicationContext(), TestAlarmManagerActivity.class));
                break;
            }
            case 6: {//测试baseActivity
                startActivity(new Intent(getApplicationContext(), TestBaseActivity.class));
                break;
            }
            case 7: {//测试视频播放
                startActivity(new Intent(getApplicationContext(), TestVideoPlayActivity.class));
                break;
            }
            case 8: {//测试背景音乐的开启关闭
                startActivity(new Intent(getApplicationContext(), TestAudioMuteActivity.class));
                break;
            }
            case 9: {//测试背景音乐的开启关闭1
                startActivity(new Intent(getApplicationContext(), TestAudioMute1Activity.class));
                break;
            }
            case 10: {//测试ContentProvider
                startActivity(new Intent(getApplicationContext(), TestContentProviderActivity.class));
                break;
            }
            case 11: {//测试发送短信
                startActivity(new Intent(getApplicationContext(), TestSendSMSActivity.class));
                break;
            }
            case 12: {//测试Activity的启动模式
                startActivity(new Intent(getApplicationContext(), TestActivityA.class));
                break;
            }
            case 13: {//测试Handler Looper MessageQueue
                startActivity(new Intent(getApplicationContext(), TestHandlerLoopMessageQueueActivity.class));
                break;
            }
            case 14: {
                startActivity(new Intent(getApplicationContext(), TestLayoutAnimationActivity.class));
                break;
            }
            case 15: {
                startActivity(new Intent(getApplicationContext(), TestViewPropertyAnimatorActivity.class));
                break;
            }
            case 16: {
                startActivity(new Intent(getApplicationContext(), TestAnimWithTouchEventActivity.class));
                break;
            }
            case 17: {
                startActivity(new Intent(getApplicationContext(), TestCustomViewActivity.class));
                break;
            }
            case 18: {
                startActivity(new Intent(getApplicationContext(), TestOnMeasureAndOnLayoutActivity.class));
                break;
            }
            case 19: {
                startActivity(new Intent(getApplicationContext(), TestCoordinatorLayoutActivity.class));
                break;
            }
            case 20: {
                startActivity(new Intent(getApplicationContext(), TestFloatingActionButtonActivity.class));
                break;
            }
            case 21: {
                startActivity(new Intent(getApplicationContext(), TestLaunchActivity.class));
                break;
            }
            case 22: {
                startActivity(new Intent(getApplicationContext(), TestViewActionDispatchActivity.class));
                break;
            }
            case 23: {
                startActivity(new Intent(getApplicationContext(), TestFileIOActivity.class));
                break;
            }
            case 24: {
                startActivity(new Intent(getApplicationContext(), TestViewActionConflictActivity.class));
                break;
            }
            case 25: {
                startActivity(new Intent(getApplicationContext(), TestSocketClientActivity.class));
                break;
            }
            case 26: {
                startActivity(new Intent(getApplicationContext(), TestSimpleSocketClientActivity.class));
                break;
            }
            case 27: {
                startActivity(new Intent(getApplicationContext(), TestMultiProcessActivity.class));
                break;
            }
            case 28: {
                startActivity(new Intent(getApplicationContext(), TestActivityConnectServiceActivity.class));
                break;
            }
            case 29: {
                startActivity(new Intent(getApplicationContext(), TestTraceViewActivity.class));
                break;
            }
            case 30: {
                startActivity(new Intent(getApplicationContext(), TestDrawableActivity.class));
                break;
            }
            case 31: {
                startActivity(new Intent(getApplicationContext(), TestClipDrawableActivity.class));
                break;
            }

        }
    }


}
